import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:seedfour/app/models/case_list_entity.dart';
import 'package:seedfour/app/widget/null_tip.dart';

import '../../../constants.dart';
import 'logic.dart';

class CaseQueryPage extends StatelessWidget {
  CaseQueryPage({Key? key}) : super(key: key);

  final logic = Get.find<CaseQueryLogic>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('案件查询'),
        leading: IconButton(
          icon: Icon(
            Icons.arrow_back_ios,
            size: 16.w,
          ),
          onPressed: () {
            Get.back();
          },
        ),
      ),
      body: logic.caseList.isEmpty
          ? const NullTip()
          : ListView.separated(
              separatorBuilder: (BuildContext context, int index) => Padding(
                  padding: EdgeInsets.symmetric(horizontal: kSpaceSmall),
                  child: const Divider()),
              itemBuilder: _renderRow,
              itemCount: logic.caseList.length,
            ),
    );
  }

  Widget _valueText(String? value) {
    return Expanded(
      child: Text(
        value ?? '',
        style: TextStyle(
          fontSize: kFontSizeMedium,
          color: Colors.black87,
        ),
      ),
    );
  }

  Widget _labelText(String value) {
    return SizedBox(
      width: 90.w,
      child: Text(
        value,
        style: TextStyle(
          fontSize: kFontSizeMedium,
          color: Colors.grey,
        ),
      ),
    );
  }

  List<Widget> _itemBuilder(CaseInfo item) {
    return [
      Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [_labelText('案件名称'), _valueText(item.caseName)]),
      SizedBox(height: kSpaceMini),
      Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [_labelText('案件号'), _valueText(item.id)]),
      SizedBox(height: kSpaceMini),
      Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            _labelText('案件状态'),
            _valueText(caseStatus[item.caseStatus])
          ]),
      SizedBox(height: kSpaceMini),
      Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [_labelText('案件负责人'), _valueText(item.takerStr)]),
      SizedBox(height: kSpaceMini),
      Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [_labelText('创建时间'), _valueText(item.createdAtStr)]),
      SizedBox(height: kSpaceMini),
      Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            _labelText('委托人名称'),
            Expanded(
              child: Align(
                alignment: Alignment.centerRight,
                child: Html(data: item.clientName),
              ),
            ),
          ]),
      // SizedBox(height: kSpaceMini),
      // Row(
      //     crossAxisAlignment: CrossAxisAlignment.center,
      //     mainAxisAlignment: MainAxisAlignment.start,
      //     children: [_labelText('利益相对方'), _valueText(item.oppositeName)]),
      // SizedBox(height: kSpaceTiny),
      // Row(
      //     crossAxisAlignment: CrossAxisAlignment.center,
      //     mainAxisAlignment: MainAxisAlignment.start,
      //     children: [_labelText('第三方'), _valueText(item.thirdName)]),
    ];
  }

  Widget _renderRow(BuildContext context, int index) {
    return Padding(
      padding: EdgeInsets.all(kSpaceSmall),
      child: Column(
        children: _itemBuilder(logic.caseList[index]),
      ),
    );
  }
}
